# 1.用for循环和while循环来完成简单的计数

counter = 0
for e in range(10):
    print(counter)

i = 0
while i < 10:
    print(i)
    i += 1

# 2.用for循环和while循环两种方式来实现斐波那契函数
def fib(n):
    if n == 1:
        return [0]
    elif n == 2:
        return [0, 1]
    elif n > 2:
        fibs = [0, 1]
        for i in range(2, n):
            fibs.append(fibs[-2] + fibs[-1])
        return fibs


print(fib(int(input("请输入多少位斐波那契数列？"))))

print("----------------")


a = 0
b = 1
list2 = [0]
n = int(input("请输入你需要几位斐波那契数列？（2~100）"))
while n > 0:
    list2.append(b)
    a, b = b, a + b
    n -= 1
    print(list2)


# 3.在第二周_第一节课我们实现的简单计算器的基础上，对参数进行检查，如果报错就抛出我们自定义异常ParamsError

class ParamsError(Exception):
    pass


def addition(a, b):
    result = a + b
    return result


def subtraction(a, b):
    result = a - b
    return result


def multiplication(a, b):
    result = a * b
    return result


def division(a, b):
    try:
        result = a / b
    except ZeroDivisionError:
        raise ParamsError("分母不可以为0")
    return result


def exact_division(a, b):
    try:
        result = a // b
    except ZeroDivisionError:
        raise ParamsError("分母不可以为0")
    return result


def modulus(a, b):
    result = a % b
    return result


def exponent(a, b):
    result = a ** b
    return result


def sqrt(a):
    result = a ** (1/2)
    return result



z = addition(1, 2)
print(z)

y = subtraction(5, 6)
print(y)

x = multiplication(5, 7)
print(x)

m = division(9, 0)
print(m)

n = exact_division(123, 51)
print(n)

o = modulus(5, 4)
print(o)

p = exponent(2, 8)
print(p)

r = sqrt(0)
print(r)










